var $currentCaseId = 0;

__CreateJSPath = function (js) {
    var scripts = document.getElementsByTagName("script");
    var path = "";
    for (var i = 0, l = scripts.length; i < l; i++) {
        var src = scripts[i].src;
        if (src.indexOf(js) != -1) {
            var ss = src.split(js);
            path = ss[0];
            break;
        }
    }
    var href = location.href;
    href = href.split("#")[0];
    href = href.split("?")[0];
    var ss = href.split("/");
    ss.length = ss.length - 1;
    href = ss.join("/");
    if (path.indexOf("http:") == -1 && path.indexOf("file:") == -1) {
        path = href + "/" + path;
    }
    return path;
}
var bootPATH = __CreateJSPath("index.js");
document.write('<script type="text/javascript" src="'+bootPATH+'/commentList.js"></script>');
document.write('<script type="text/javascript" src="'+bootPATH+'/caseList.js"></script>');
document.write('<script type="text/javascript" src="'+bootPATH+'/adminList.js"></script>');
document.write('<script type="text/javascript" src="'+bootPATH+'/userList.js"></script>');
document.write('<script type="text/javascript" src="'+bootPATH+'../dataSource.js"></script>');

//加载登录界面
function loadLoginPage(){
	$('#centerPanel').panel({   
	    href:'login.jsp',
	    onLoad:loginPage
	});
}

//加载留言管理页面
function loadCommentListPage(){
	$('#centerPanel').panel({   
	    href:'commentList.jsp',
	    onLoad:loadSucCommentList
	}); 
}
//加载案例管理页面
function loadCaseListPage(){
	$('#centerPanel').panel({   
	    href:'caseList.jsp',
	    onLoad:loadSucCaseList
	}); 
}

//清除信息
function clearForm(formId) {
	$('#'+formId).form('clear');
}

// 加载成功触发
function onLoadSuccess(data) {
	var page = $(this).datagrid("getPager");
	page.pagination({
	    onSelectPage : function(pageNumber, pageSize) {
		    loadGridData(pageNumber, pageSize, this);
	    },
	    
	    onChangePageSize : function(pageSize) {
		    page.pagination({
		        pageNumber : 1,
		        pageSize : pageSize
		    });
	    }
	});
}

// 分页插件页面变换
function loadGridData(pageNumber, pageSize, target) {
	if ($("#commentList").length == 1)
		queryComment(pageNumber, pageSize);
	if ($("#caseList").length == 1)
		queryCase(pageNumber, pageSize);
}

//加载数据datagrid数据
function loadDataGirdJson(url,param,target){
	$.post(url,param,function(text){
		var data = (new Function("return "+text))();
		$(target).datagrid("loadData",data);
		var pager = $(target).datagrid('getPager');
		pager.pagination({   
        	total:data.total,pageNumber:param.pageNum,pageSize:param.pageSize
		}); 
	});
}

//打开修改窗口
function openEditPwdWindow(){
	var diyColumnWindow = {
    		id: 'editPassWindow',
    		width: 500,
    		height: 300,
    		title: '修改密码窗口',
    		url: 'editPass.jsp',
    		collapsible: false,
    		minimizable: false,
    		maximizable: false,
    		resizable: false,
    		closable: false,
    		param: {}
    };
    OpenNewWindow(diyColumnWindow);
}

$(document).ready(function() {
	loadSysInfo();
	loadCommentListPage();
});
